package com.cloudcc.mobile.presenter;

import android.graphics.Bitmap;

import com.cloudcc.cloudframe.bus.EventEngine;
import com.cloudcc.cloudframe.bus.EventList.ChatUserInfoEvent;
import com.cloudcc.cloudframe.bus.EventList.UpdateUserEvent;
import com.cloudcc.cloudframe.model.UserModel;
import com.cloudcc.cloudframe.model.param.UpdateUserParam;
import com.cloudcc.cloudframe.model.param.UserInfoParam;
import com.cloudcc.cloudframe.util.StringUtils;
import com.cloudcc.mobile.dao.UserEngine;
import com.cloudcc.mobile.dao.impl.UserEngineImpl;
import com.cloudcc.mobile.manager.UserManager;
import com.cloudcc.mobile.util.ImageUtils;

public class UserPresenter extends BasePresenter {
	private UserEngine userEngine;

	public UserPresenter() {
		super();
		userEngine = new UserEngineImpl();
	}

	/**
	 * 获得用户详情
	 */
	public void getUserInfo() {
		ChatUserInfoEvent event = new ChatUserInfoEvent();
		if (!UserManager.getManager().isLogin()) {
			event.setOk(false);
			event.setMessage("未登录,请重新登录！");
			EventEngine.post(event);
			return;
		}
		UserInfoParam param = new UserInfoParam();

		param.isReturnChatter = false;
		param.userId = UserManager.getManager().getUser().userId;

		userEngine.getChatUserInfo(param, event);

	}

	public void UpdateLogo(Bitmap photo, UserModel chatUser) {
		UpdateUserEvent event = new UpdateUserEvent();
		if (photo == null) {
			event.setOk(false);
			event.setMessage("图片不能为空!");
			EventEngine.post(event);
			return;
		}
		String logo = ImageUtils.bitmapToBase64(ImageUtils.yasuoImage(photo));
		if (StringUtils.isBlank(logo)) {
			event.setOk(false);
			event.setMessage("图片压缩失败！");
			EventEngine.post(event);
			return;
		}
		if (chatUser == null) {
			event.setOk(false);
			event.setMessage("参数错误。。");
			EventEngine.post(event);
			return;
		}
		UpdateUserParam param = new UpdateUserParam();
		param.email = chatUser.email;
		param.phone = chatUser.phone;
		param.mobile = chatUser.phone;
		param.aboutme = "";
		param.address = "";
		param.title = "";
		param.imgStr = logo;
		userEngine.updateUser(param, event);

	}

}
